home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / STACY / STUNIT.S < prev    next >
Encoding:
Text File  |  2001-02-09  |  4.1 KB  |  174 lines

  1. flock        equ    $43e        ; FIFO lock variable
  2. _hz_200        equ    $4ba        ; system 200hz timer
  3.  
  4. SHIP        equ    0        ; flag to stop ACSI unit 0
  5. UNSHIP        equ    1        ; flag to restart ACSI unit 0
  6.  
  7. wdc        equ    $ffff8604
  8. wdl        equ    $ffff8606
  9. wdcwdl        equ    wdc        ; used for long writes
  10. xwdl        equ    wdl-wdc        ; offset from wdc to wdl
  11.  
  12. dmahi        equ    $ffff8609
  13. dmamid        equ    dmahi+2
  14. dmalow        equ    dmamid+2
  15. gpip        equ    $fffffa01
  16.  
  17. slwstmout    equ    42        ; short-timeout (205 mS) for slow ACSI
  18. slwltmout    equ    2000        ; long-timeout (30 S) for slow ACSI
  19.  
  20.  
  21. main:    move.l    #0,-(sp)    ; NULL
  22.     move.w    #$20,-(sp)    ; Super(0L)
  23.     trap    #1
  24.     addq.w    #6,sp        ; cleanup stack
  25.     move.l    d0,savssp    ; save stack pointer
  26.     move.w    #SHIP,-(sp)    ; stop the unit
  27.     move.w    #0,-(sp)    ; ACSI unit 0
  28.     bsr    _stunit        ; stunit(physunit, SHIP)
  29.     addq.w    #4,sp        ; clean up stack
  30.     move.w    #UNSHIP,-(sp)    ; stop the unit
  31.     move.w    #0,-(sp)    ; ACSI unit 0
  32.     bsr    _stunit        ; stunit(physunit, UNSHIP)
  33.     addq.w    #4,sp        ; clean up stack
  34.     move.l    savssp,-(sp)    ; saved stack pointer
  35.     move.w    #$20,-(sp)    ; Super(savssp)
  36.     trap    #1
  37.     addq.w    #6,sp        ; cleanup stack
  38.     move.w    #0,-(sp)    ; Pterm0
  39.     trap    #1
  40.     illegal            ; should never come back
  41.  
  42. savssp:    dc.l    0
  43.  
  44. ;----------------
  45. ;
  46. ; LONG _qdone() - Wait for command byte handshake
  47. ; LONG _fdone() - Wait for operation complete
  48. ; Passed:    nothing
  49. ;
  50. ; Returns:    EQ: no timeout
  51. ;        MI: timeout condition
  52. ;
  53. ; Uses:        D0
  54. ;
  55. ;
  56. ;-
  57. _slwfdone:                ; fdone for slow ACSI devices
  58.     move.l    #slwltmout,d0        ; wait 30 seconds
  59.     bra.s    qd1
  60.  
  61. _slwqdone:                ; qdone for slow ACSI devices
  62.     moveq    #slwstmout,d0        ; wait 200 milliseconds
  63.  
  64. qd1:    add.l    _hz_200,d0
  65. qd2:    cmp.l    _hz_200,d0        ; timeout?
  66.     bcs.s    qdq            ; (i give up, return NE)
  67.     btst    #5,gpip            ; interrupt?
  68.     bne.s    qd2            ; (not yet)
  69.  
  70.     moveq    #0,d0            ; return EQ (no timeout)
  71.     rts
  72.  
  73. qdq:    moveq    #-1,d0
  74.     rts
  75.  
  76.  
  77. ;----------------
  78. ;
  79. ; Wait for end of SASI command
  80. ;
  81. ; Passed:    d0 value to be written to wdl
  82. ;
  83. ; Returns:    EQ: success (error code in D0.W)
  84. ;        MI: timeout (-1 in D0.W)
  85. ;        NE: failure (SASI error code in D0.W)
  86. ;
  87. ; Uses:        d0,d1
  88. ;-
  89. _slwendcmd:
  90.     move    d0,d1            ; preserve wdl value
  91.     bsr    _slwfdone        ; wait for operation complete
  92.  
  93. end1:    bmi.s    endce            ; (timed-out, so complain)
  94.  
  95.     move.w    d1,wdl
  96.     move.w    wdc,d0            ; get the result
  97.     and.w    #$00ff,d0        ; (clean it up), if non-zero should
  98.                     ; do a ReadSense command to learn more
  99. endce:    move.l    _hz_200,lastacstm    ; update controller last accessed time
  100.     addq.l    #2,lastacstm        ; lastacstm = _hz_200 + 2;
  101.     rts                
  102.  
  103.  
  104. ;+
  105. ;  Handle command timeout;
  106. ;  Unlock DMA chip and return completion status;
  107. ;-
  108. _hto:    moveq    #-1,d0        ; indicate timeout
  109. _hdone:    move.w    #$80,wdl    ; Landon's code seems to presume we
  110.     tst.w    wdc
  111.     sf    flock        ; NOW, signal that we are done
  112.     rts
  113.  
  114.  
  115. lastacstm:    dc.l    0
  116.  
  117. ;+
  118. ; delay()
  119. ;    5 - 10ms kludge delay for message byte sent back by controller.
  120. ;-
  121. _delay:    move.l    lastacstm,d0        ; d0 = controller last accessed time
  122. wait:    cmp.l    _hz_200,d0        ; while (_hz_200 <= lastacstm)
  123.     bcc.s    wait            ;    wait()
  124.     rts
  125.  
  126. ;----------------
  127. ;
  128. ;  stunit - Start/Stop unit
  129. ;
  130. ;    Synopsis:    LONG stunit(dev, flag)
  131. ;        WORD dev;        4(sp).W
  132. ;        WORD flag;        6(sp).W
  133. ;
  134. ;    Uses:  d0, d1, and a0
  135. ;-
  136. stcmd:    dc.b    $1b    ; start/stop command + devno (upper 3 bits)
  137.     dc.b    0    ; (unused)
  138.     dc.b    0    ; (unused)
  139.     dc.b    0    ; (unused)
  140.     dc.b    0    ; bit 0 = to flag start or stop unit
  141.     dc.b    0    ; (unused)
  142. .even
  143.  
  144. _stunit:
  145.     bsr    _delay
  146.     move.w    4(sp),d0        ; set dev#
  147.     lsl.b    #5,d0            ; up 5 bits, fill in 0s
  148.     lea    stcmd,a0        ; pick up pointer to the command block
  149.     or.b    d0,(a0)            ; stuff dev # into command frame
  150.     move.b    7(sp),4(a0)        ; stuff flag into command frame
  151.     moveq    #0,d0            ; clear d0
  152.     st    flock            ; lock FIFO
  153.     move.w    #$88,wdl
  154.     move.b    (a0)+,d0        ; get the command byte
  155.     swap    d0
  156.     move.w    #$8a,d0
  157.     move.l    d0,wdcwdl        ; byte wdc 8a wdl
  158.     
  159.     moveq    #(5-1),d1        ; write next 5 bytes of command
  160. st1:    bsr    _slwqdone
  161.     bmi    _hto
  162.     move.b    (a0)+,d0        ; next byte of command
  163.     swap    d0
  164.     move.w    #$8a,d0
  165.     move.l    d0,wdcwdl        ; byte wdc 8a wdl
  166.     dbra    d1,st1
  167.     bsr    _slwendcmd        ; wait for command completion
  168.     moveq    #2,d1            ; /* ~ 5 millisecond delay */
  169.     add.l    _hz_200,d1        ; /* for slow acsi devices */
  170. .0:    cmp.l    _hz_200,d1        ;
  171.     bcc.s    .0            ;
  172.     bra    _hdone            ; cleanup after IRQ
  173.  
  174.